<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <!-- 注意 vue-resource 依赖于Vue 所以先后顺序不能反 -->
    <!-- this.$http.jsonp -->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://cdn.bootcss.com/vue-resource/1.5.1/vue-resource.js"></script>
</head>
<body>
    <div id="app">
        <input type="button" value="get请求" @click="getInfo">
        <input type="button" value="post请求" @click="postInfo">
        <input type="button" value="jsonp请求" @click="jsonpInfo">
    </div>

    <script>
        var vm = new Vue({
            el: '#app',
            data: {

            },
            methods: {
                getInfo() { // 发起get请求 this.$http.get('/someUrl', [config]).then(successCallback, errorCallback);
                    this.$http.get('http://127.0.0.1:8041/front/users').then(function (result){
                        // 通过
                        console.log(result)
                    })
                },
                postInfo() { // 发起post请求 this.$http.post('/someUrl', [body], [config]).then(successCallback, errorCallback);
                    // 手动发起的post请求，默认没有表单格式，所以有的服务器处理不了
                    // 如果后端post方法中必须接收的是表单类型就需要通过post方法的第三个参数，设置提交的内容类型为普通表单数据格式(emulateJSON: true)
                    this.$http.post('http://localhost:8041/front/user/add',{
	                        "loginName": "飞天adfa",
	                        "password": "abcddfad"
                    },{}).then(result => {
                        console.log(result.body)
                    })
                },
                jsonpInfo() { // 发送Jsonp请求
                    this.$http.jsonp('').then(result => {
                        console.log(result.body)
                    })
                }
            }
        })
    
    </script>
</body>
</html>